package com.tledu.zyf.servlet.user;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tledu.zyf.model.User;
import com.tledu.zyf.util.ForwardUtil;
import com.tledu.zyf.util.ObjectFactory;

/**
 * 模糊查询
 * 
 * @author yingfing
 * @date 2020年10月3日 @time 下午8:19:57
 */
@WebServlet("/user/vagueUsername")
public class UserVagueUsernameServlet extends HttpServlet {
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 获取传递的数据
		String username = request.getParameter("username");
		// 调用 vagueUsername 方法 , 获取所有的用户数据
		List<User> users = ObjectFactory.getUserService().vagueUsername(username);
		for (User user2 : users) {
			System.out.println(user2);
		}
		// 传递到页面
		request.setAttribute("users", users);

		// 跳转到对应的展示页面
		ForwardUtil.forward(request, response, "user/list");
//		request.getRequestDispatcher("/WEB-INF/jsp/user/list.jsp").forward(request, response);

	}
}
